//
//  ZYCSchoolAttendanceStaticsBottomView.m
//  ZDSC
//
//  Created by 张威 on 2021/10/20.
//

#import "ZYCSchoolAttendanceStaticsBottomView.h"
#import "ZYCAttendanceStatusGroupView.h"
#import "ZYCSchoolAttendanceStatisticsModel.h"

@interface ZYCSchoolAttendanceStaticsBottomView ()

@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *numLabel;
@property (nonatomic, strong) UIView *bgView;

// 早退
@property (nonatomic, strong) ZYCAttendanceStatusGroupView *leaveEarlyGroupView;
// 迟到
@property (nonatomic, strong) ZYCAttendanceStatusGroupView *lateGroupView;
// 请假
@property (nonatomic, strong) ZYCAttendanceStatusGroupView *leaveGroupView;
// 缺卡
@property (nonatomic, strong) ZYCAttendanceStatusGroupView *missingCardGroupView;
// 加班
@property (nonatomic, strong) ZYCAttendanceStatusGroupView *workOvertimeGroupView;
@end

@implementation ZYCSchoolAttendanceStaticsBottomView

- (void)setModel:(ZYCSchoolAttendanceStatisticsModel *)model{
    _model = model;
    _numLabel.attributedText = [self returnStringWithString:model.countDKAndYD];
    _leaveEarlyGroupView.count = model.countZT;
    _lateGroupView.count = model.countCD;
    _leaveGroupView.count = model.countQJ;
    _missingCardGroupView.count = model.countQK;
    _workOvertimeGroupView.count = model.countJB;
}

- (NSMutableAttributedString *)returnStringWithString:(NSString *)string{
    NSMutableAttributedString * attriString = [[NSMutableAttributedString alloc] initWithString:string];
    NSRange range = [string rangeOfString:@"/"];
    [attriString addAttribute:NSForegroundColorAttributeName value:HEX_RGB(@"#EC4402") range:NSMakeRange(0, range.length)];
    return attriString;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.bgView];
        [self addSubview:self.titleLabel];
        [self addSubview:self.numLabel];
        [self.bgView addSubview:self.lateGroupView];
        [self.bgView addSubview:self.leaveEarlyGroupView];
        [self.bgView addSubview:self.missingCardGroupView];
        [self.bgView addSubview:self.leaveGroupView];
        [self.bgView addSubview:self.workOvertimeGroupView];
        
        CGFloat margin  = (kScreenWidth - 20 - 50 * 4) / 5;
        
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(10.0f);
            make.top.equalTo(self).offset(20.0f);
        }];
        
        [self.numLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.titleLabel.mas_right).offset(5.0f);
            make.centerY.equalTo(self.titleLabel);
        }];
        
        [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(10.0f);
            make.top.equalTo(self.titleLabel.mas_bottom).offset(18.0f);
            make.bottom.right.equalTo(self).offset(-10.0f);
        }];
        
        // 早退
        [self.leaveEarlyGroupView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(50, 70));
            make.left.equalTo(self.bgView).offset(margin);
            make.top.equalTo(self.bgView).offset(17.5f);
            
        }];
        // 迟到
        [self.lateGroupView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(50, 70));
            make.left.equalTo(self.leaveEarlyGroupView.mas_right).offset(margin);
            make.centerY.equalTo(self.leaveEarlyGroupView);
        }];
        // 请假
        [self.leaveGroupView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(50, 70));
            make.left.equalTo(self.lateGroupView.mas_right).offset(margin);
            make.centerY.equalTo(self.leaveEarlyGroupView);
        }];
  

        // 缺卡
        [self.missingCardGroupView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(50, 70));
            make.left.equalTo(self.leaveGroupView.mas_right).offset(margin);
            make.centerY.equalTo(self.leaveEarlyGroupView);
        }];
        

        [self.workOvertimeGroupView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(50, 70));
            make.left.equalTo(self.bgView).offset(margin);
            make.top.equalTo(self.leaveEarlyGroupView.mas_bottom).offset(17.5f);
        }];
    }
    return self;
}

- (UIView *)bgView {
    if (!_bgView) {
        _bgView = [[UIView alloc] init];
        _bgView.backgroundColor = HEX_RGB(kBgWhiteColor);
        _bgView.layer.cornerRadius = 7.5f;
        _bgView.layer.masksToBounds = YES;
    }
    return _bgView;
}

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [UILabel LabelWithString:@"打卡人数/应到人数" Font:kCustomFont(@"PingFangSC-Regular", 13.0f) titleColor:HEX_RGB(@"999999") textAlignment:ZZTextAlignmentLeft];
    }
    return _titleLabel;
}

- (UILabel *)numLabel {
    if (!_numLabel) {
        _numLabel = [UILabel LabelWithString:@"加载中..." Font:kSystemBoldFont(18.0f) titleColor:HEX_RGB(@"333333") textAlignment:ZZTextAlignmentLeft];
    }
    return _numLabel;
}

- (ZYCAttendanceStatusGroupView *)leaveEarlyGroupView {
    if (!_leaveEarlyGroupView) {
        _leaveEarlyGroupView = [[ZYCAttendanceStatusGroupView alloc] init];
        _leaveEarlyGroupView.color = HEX_RGB(@"#2B7BBF");
        _leaveEarlyGroupView.title = @"早退";
    }
    return _leaveEarlyGroupView;
}

- (ZYCAttendanceStatusGroupView *)lateGroupView {
    if (!_lateGroupView) {
        _lateGroupView = [[ZYCAttendanceStatusGroupView alloc] init];
        _lateGroupView.color = HEX_RGB(@"#F05850");
        _lateGroupView.title = @"迟到";
    }
    return _lateGroupView;
}

- (ZYCAttendanceStatusGroupView *)leaveGroupView {
    if (!_leaveGroupView) {
        _leaveGroupView = [[ZYCAttendanceStatusGroupView alloc] init];
        _leaveGroupView.color = HEX_RGB(@"#FDAC5C");
        _leaveGroupView.title = @"请假";
    }
    return _leaveGroupView;
}


- (ZYCAttendanceStatusGroupView *)missingCardGroupView {
    if (!_missingCardGroupView) {
        _missingCardGroupView = [[ZYCAttendanceStatusGroupView alloc] init];
        _missingCardGroupView.color = HEX_RGB(@"#C1C1C1");
        _missingCardGroupView.title = @"缺卡";
    }
    return _missingCardGroupView;
}

- (ZYCAttendanceStatusGroupView *)workOvertimeGroupView {
    if (!_workOvertimeGroupView) {
        _workOvertimeGroupView = [[ZYCAttendanceStatusGroupView alloc] init];
        _workOvertimeGroupView.color = HEX_RGB(@"#39B5A0");
        _workOvertimeGroupView.title = @"加班";
    }
    return _workOvertimeGroupView;
}

@end
